package com.atguigu.gulimall.search.web;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.atguigu.gulimall.search.service.MallSearchService;
import com.atguigu.gulimall.search.vo.SearchParams;
import com.atguigu.gulimall.search.vo.SearchResult;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class SearchController {

    @Autowired
    MallSearchService mallSearchService;


    @GetMapping({"/","list.html"})
    public String list(SearchParams params, Model model){
        SearchResult result = mallSearchService.search(params);
        System.out.println(JSONObject.toJSON(result));

        model.addAttribute("params",params);
        model.addAttribute("result",result);

        return "list";
    }
}
